package com.uenpay.im.ui.old.activity.red;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class GetRedOpenYearInvokItem extends HttpInvokeItem {

	public class GetRedOpenYearInvokItemResult extends HttpInvokeResult {
		public ArrayList<String> years = new ArrayList<String>();
	}

	public GetRedOpenYearInvokItemResult getOutput() {
		return (GetRedOpenYearInvokItemResult) GetResultObject();
	}

	public GetRedOpenYearInvokItem() {
		String url = APIConfiguration.getBaseUrl()
				+ "Purse/RedPackets/packetsOpenYear?"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GetRedOpenYearInvokItemResult result = new GetRedOpenYearInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONArray jsonObject = json.optJSONArray("data");
			if (jsonObject == null) {
				return result;
			}
			for (int i = 0, length = jsonObject.length(); i < length; i++) {
				result.years.add(jsonObject.optString(i));
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}
		return result;
	}

}
